﻿/*
	SWFListMaker
	
	*** Updated 7.9.2005 to look for contiousplayback and looping in XML.
	*** Updated 3.13.2005 to use a new classpath.
	
	Reads a CaptivatePlayer Playlist, an XML
	file that holds a list of the SWF's to play
	as well as configuration information
	for the player that overrides what
	FlashVars sets.
	
	Created by Jesse R. Warden a.k.a. "JesterXL"
	jesterxl@jessewarden.com
	http://www.jessewarden.com
	11.19.2004
	
	This is release under a Creative Commons license. 
    More information can be found here:
    
    http://creativecommons.org/licenses/by/2.5/
*/


import mx.events.EventDispatcher;
import mx.controls.listclasses.DataProvider;

class com.jxl.captivate.SWFListMaker extends XML
{
	static var mixIt:Boolean = DataProvider.Initialize(Array);
	static var mixIt2 = EventDispatcher.initialize(SWFListMaker.prototype);
	
	public var addEventListener:Function;
	public var removeEventListener:Function;
	private var dispatchEvent:Function;
	
	function SWFListMaker()
	{
		init.apply(this, arguments);
	}
	
	public function init(p_xmlstr:String):Void
	{
		if(p_xmlstr != null)
		{
			this.parseXML(p_xmlstr);
		}
		
		this.ignoreWhite = true;
	}
	
	public function loadXML(filepath:String):Void
	{
		this.load(filepath);
	}
	
	public function onLoad(success:Boolean):Void
	{
		var a:Array = [];
		var swfNodes:XMLNode = this.firstChild;
		var swfNode_array:Array = swfNodes.childNodes;
		var i:Number = swfNode_array.length;
		while(i--)
		{
			var node:XMLNode = swfNode_array[i];
			var o:Object = {};
			o.label = node.attributes.name;
			o.data = node.attributes.src;
			a.addItem(o);
		}
		a.reverse();
		
		var autoplay:Boolean = (swfNodes.attributes.autoplay.toLowerCase() == "false") ? false : null;
		var value:String = swfNodes.attributes.volume;
		var volume:Number = (value == null) ? null : parseInt(value);
		var scalecontent:Boolean = (swfNodes.attributes.scalecontent.toLowerCase() == "false") ? false : null;
		var continousplayback:Boolean = (swfNodes.attributes.continousplayback.toLowerCase() == "false") ? false : true;
		var looping:Boolean = (swfNodes.attributes.looping.toLowerCase() == "true") ? true : false;
		dispatchEvent({type: "load", target: this, 
					  results: a,
					  autoplay: autoplay,
					  volume: volume,
					  continousplayback: continousplayback,
					  looping: looping,
					  scalecontent: scalecontent});
	}
}